from django.db import models


# Create your models here.


# 学生模型
class Student(models.Model):
    SEX_CHOICES = ((1, '男'), (0, '女'))
    # auth 后台显示的字段名
    name = models.CharField(max_length=20, verbose_name='姓名')
    # null = True 后端可以为空 blank = True 前端可以为空,不传数据
    age = models.IntegerField(null=True, blank=True, verbose_name='年龄')
    sex = models.IntegerField(null=True, blank=True, verbose_name='性别', choices=SEX_CHOICES)
    created_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')
    updated_time = models.DateTimeField(auto_now=True, verbose_name='更新时间')
    # 数据删除 逻辑删除 查询的过滤条件
    is_delete = models.BooleanField(default=False, verbose_name='逻辑删除')
    classes = models.ForeignKey('Classes', on_delete=models.SET_NULL, null=True, verbose_name='班级')

    class Meta:
        db_table = 'student'

    def delete(self):
        # 是修改
        self.is_delete = True
        self.save()


class Classes(models.Model):
    name = models.CharField(max_length=20, verbose_name='班级')
    slogan = models.TextField(null=True, blank=True, verbose_name='班级口号')
    created_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')
    updated_time = models.DateTimeField(auto_now=True, verbose_name='更新时间')
    is_delete = models.BooleanField(default=False, verbose_name='逻辑删除')

    class Meta:
        db_table = 'classes'

    def __str__(self):
        return self.name

    # 模型对象.方法()
    def delete(self):
        # 修改 逻辑删除 不要删除数据库里的 删除前端展示的
        self.is_delete = True
        self.save()
